package cl.tienda.control;

import cl.tienda.modelo.Producto;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.Vector;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Marcoltx and AndrsKaiser
 */
public class ServletCConProd extends HttpServlet {

    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
       doPost(request, response);
    } 
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       
    
        PrintWriter out = response.getWriter(); 
        Vector<Producto> productos=(Vector<Producto>)request.getSession().getAttribute("productos");
        
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Consultar Producto</title>");
            out.println("<style type=\"text/css\">");
            out.println("<!--");
            out.println("body {");
            out.println("background-color: #FFFF99;");
            out.println("}");
            out.println("body,td,th {");
            out.println("font-family: Arial, Helvetica, sans-serif;");
            out.println("}");
            out.println("</style>");
            out.println("</head>");
            out.println("<body>");
            out.println("<table width=\"800\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">");
            out.println("<tr>");
            out.println("<td width=\"84\" bgcolor=\"#FF0000\"><img src=\"carritoxd.jpg\" width=\"84\" height=\"77\"/></td>");
            out.println("<td width=\"716\" bgcolor=\"#FF0000\"><h1 style=\"color:#FFFFFF\">Carrito de Compras</h1></td>");
            out.println("</tr>");
            out.println("<tr align=\"center\">");
            out.println("<td colspan=\"2\">&nbsp;</td>");
            out.println("</tr>");
            out.println("<tr align=\"center\">");
            out.println("<td colspan=\"2\">");
            out.println("<h4><a href=\"ServletCConProd\">Consultar Productos</a> | <a href=\"ServletCAgrCarrito1\">Agregar al Carrito</a> | <a href=\"login.html\">Salir</a></h4></td>");
            out.println("</tr>");
            out.println("<tr>");
            out.println("<td colspan=\"2\">&nbsp;</td>");
            out.println("</tr>");
            out.println("<tr>");
            out.println("<td coldspan=\"2\"><table width=\"500%\" border=\"2\">");
            out.println("<tr bgcolor=\"#FF6600\" style=\"color: #FFFFFF\">");
            out.println("<td width=\"68%\"><h4>Nombre</h4></td>");
            out.println("<td width=\"16%\" align=\"right\" valign=\"top\"><h4><span class=\"Color3\">Stock</span></h4></td>");
            out.println("<td width=\"16%\" align=\"right\" valign=\"top\"><h4><span class=\"Color3\">Precio</span></h4></td>");
            out.println("</tr>");
            
            for(int i=0; i<productos.size(); i++){
                if(i%2==0){
                    out.println("<tr bgcolor=\"#FFFFFF\">");
                    out.println("<td>" +productos.get(i).getNombreProducto()+"</td>");
                    out.println("<td align=\"right\" valign=\"top\">"+ productos.get(i).getStock() +"</td>");
                    out.println("<td align=\"right\" valign=\"top\">"+ productos.get(i).getPrecio() +"</td>");
                    out.println("</tr>");
                } else {
                    out.println("<tr>");
                    out.println("<td>"+productos.get(i).getNombreProducto()+ "</td>");
                    out.println("<td align=\"right\" valign=\"top\">"+productos.get(i).getStock()+"</td>");
                    out.println("<td align=\"right\" valign=\"top\">"+productos.get(i).getPrecio()+"</td>");
                    out.println("</tr>");
                }
            }
            out.println("</table></td>");
            out.println("</tr>");
            out.println("<tr>");
            out.println("<td colspan=\"2\"&nbsp;</td>");
            out.println("</tr>");
            out.println("</table>");
            out.println("</body>");
            out.println("</html>");
            
            out.close();
            }
         
        

    @Override
    public String getServletInfo() {
        return "Short description";
    }

}